#include <iostream>

#include <boost/thread.hpp>
#include <boost/noncopyable.hpp>
#include <boost/thread/tss.hpp>

class connection : boost::noncopyable {
public:
	void open()
	{
		std::cout << "open" << std::endl;
	}
	void send_result(int result)
	{
		std::cout << "send_result " << result << std::endl;
	}
};

boost::thread_specific_ptr<connection> connection_ptr;

connection& get_connection() {
	connection* p = connection_ptr.get();
	if (!p) {
		connection_ptr.reset(new connection);
		p = connection_ptr.get();
		p->open();
	}
	std::cout << "p:" << static_cast<void*>(p) << std::endl;
	return *p;
}

void task(int param) {
	int result = param;
	get_connection().send_result(result);
}

int main()
{
	boost::thread  t1(boost::bind(&task, 1));
	boost::thread  t2(boost::bind(&task, 2));
	t1.join();
	t2.join();
	return 0;
}